﻿namespace _5._11._1.Poker
{
    using System;

    public class PokerHandsChecker : IPokerHandsChecker
    {
        public bool IsValidHand(IHand hand)
        {
            if (hand.Cards.Count != 5)
            {
                return false;
            }

            for (int i = 0; i < hand.Cards.Count - 1; i++)
            {
                for (int j = i + 1; j < hand.Cards.Count; j++)
                {
                    if (hand.Cards[i].Equals(hand.Cards[j]))
                    {
                        return false;
                    }
                }
            }

            return true;
        }

        public bool IsStraightFlush(IHand hand)
        {
            throw new NotImplementedException();
        }

        public bool IsFourOfAKind(IHand hand)
        {
            int cardsOfAKindCount = 1;
            int cardsInHand = hand.Cards.Count;

            for (int i = 0; i < cardsInHand; i++)
            {
                for (int j = i + 1; j < cardsInHand; j++)
                {
                    if (hand.Cards[i].Face == hand.Cards[j].Face)
                    {
                        cardsOfAKindCount++;
                    }
                }

                if (cardsOfAKindCount == 4)
                {
                    break;
                }

                cardsOfAKindCount = 1;
            }

            if (cardsOfAKindCount == 4)
            {
                return true;
            }

            return false;
        }

        public bool IsFullHouse(IHand hand)
        {
            throw new NotImplementedException();
        }

        public bool IsFlush(IHand hand)
        {
            for (int i = 0; i < hand.Cards.Count - 1; i++)
            {
                if (!(hand.Cards[i].Suit.Equals(hand.Cards[i + 1].Suit)))
                {
                    return false;
                }
            }

            return true;
        }

        public bool IsStraight(IHand hand)
        {
            throw new NotImplementedException();
        }

        public bool IsThreeOfAKind(IHand hand)
        {
            throw new NotImplementedException();
        }

        public bool IsTwoPair(IHand hand)
        {
            throw new NotImplementedException();
        }

        public bool IsOnePair(IHand hand)
        {
            throw new NotImplementedException();
        }

        public bool IsHighCard(IHand hand)
        {
            throw new NotImplementedException();
        }

        public int CompareHands(IHand firstHand, IHand secondHand)
        {
            throw new NotImplementedException();
        }
    }
}